# coding=utf-8
"""
作者：董新强 
创建时间：
描述：
"""
from base_handler import BaseHandler
from services.admin.ability_manage import AbilityManage
from services.admin.params_manage import ParamsManage
from services.admin.question_manage import QuestionManage
from services.admin.raw_question_manage import RawQuestionManage


class AbilityHandler(BaseHandler):
    def http_post(self):
        rt = self.req_dict('rt')
        if rt == 'status':
            return AbilityManage(self.usr).update_status(self.req_dict('id', int))
        return AbilityManage(self.usr).create_or_update(self.req_dict())

    def http_get(self):
        if 'id' in self.req_dict():
            return AbilityManage(self.usr).get_detail(self.req_dict('id', int))
        if self.req_dict('rt') == 'title':
            return AbilityManage(self.usr).get_all_title_list()

        return AbilityManage(self.usr).get_list(self.req_dict('pid', int))


class QuestionHandler(BaseHandler):
    def http_post(self):
        rt = self.req_dict('rt')
        if rt == 'delete':
            return QuestionManage(self.usr).delete(self.req_dict('id', int))
        if rt == 'recovery':
            return QuestionManage(self.usr).recovery(self.req_dict('id', int))
        return QuestionManage(self.usr).update(self.req_dict())

    def http_get(self):
        rt = self.req_dict('rt')
        if rt == 'deleted':
            return QuestionManage(self.usr).get_deleted_question_list(self.req_dict('id', int))
        if rt == 'title':
            return QuestionManage(self.usr).get_question_title_list(self.req_dict('id'))
        return QuestionManage(self.usr).get_detail(self.req_dict('id', int))


class RawQuestionHandler(BaseHandler):
    def http_post(self):
        rt = self.req_dict('rt')
        if rt == 'std':
            return RawQuestionManage(self.usr).to_std(self.req_dict('dim'), self.req_dict('aid', int))
        if rt == 'delete':
            return RawQuestionManage(self.usr).delete(self.req_dict('id', int))
        if rt == 'import':
            return RawQuestionManage(self.usr).create(self.req_dict())
        return RawQuestionManage(self.usr).update(self.req_dict())

    def http_get(self):
        rt = self.req_dict('rt')
        if rt == 'dim':
            return RawQuestionManage(self.usr).get_dim_list()
        return RawQuestionManage(self.usr).get_list(self.req_dict('dim'))


class ParamEstHandler(BaseHandler):
    def http_post(self):
        rt = self.req_dict('rt')
        if rt == 'delete':
            ParamsManage(self.usr).delete(self.req_dict('id', int))

        return ParamsManage(self.usr).update(self.req_dict('id', int))

    def http_get(self):
        rt = self.req_dict('rt')
        if rt == 'detail':
            return ParamsManage(self.usr).get_detail_list(self.req_dict('id', int))
        return ParamsManage(self.usr).get_list(self.req_dict('id', int))
